package cn.cuilan.common.entity;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class EchoMessage extends ProtocolMessage {

    public static final String PING = "0";
    public static final String PONG = "1";

    private String echo;

    public EchoMessage(String echo) {
        this.echo = echo;
    }

    @Override
    public void pack() {
        byte[] bytes = this.echo.getBytes();
        this.length = new byte[4];
        byte[] messageBytes = new byte[bytes.length + 4];
        // 复制长度
        System.arraycopy(this.length, 0, messageBytes, 0, 4);
        // 复制消息报文
        System.arraycopy(bytes, 0, messageBytes, 4, bytes.length);
        this.message = messageBytes;
    }

    @Override
    public void unpack() {
    }
}
